#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    void reverse(vector<int>& nums, int left, int right) {
        while (left < right) {
            swap(nums[left++], nums[right--]);
        }
    }
    void rotate(vector<int>& nums, int k) {
        int n = nums.size();
        k = k % n;
        reverse(nums, 0, n - 1);
        // [0, k-1] [k, n]
        reverse(nums, 0, k - 1);
        reverse(nums, k, n - 1);
    }
};